﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Meraz.Core.Model;

namespace Meraz.Core.Repositories
{
    public interface IMemberRoleRepository : IRepository<MemberRole, int> {
        List<MemberRole> Get(string applicationName);
        List<MemberRole> Get(string applicationName, string userName);
        List<MemberRole> GetByRole(string applicationName, string roleName);
    }
    public class MemberRoleRepository : EFRepositoryBase<MemberRole, int>, IMemberRoleRepository
    {
        public MemberRoleRepository() : base() {}
        public MemberRoleRepository(Data.IMerazContext context) : base(context) { }
        public override MemberRole GetById(int id)
        {
            return context.MemberRoles.Where(where1 => where1.ID == id).FirstOrDefault();
        }

        public List<MemberRole> Get(string applicationName)
        {
            return context.MemberRoles.Where(where1 => where1.ApplicationName == applicationName).ToList();
        }

        public List<MemberRole> Get(string applicationName, string userName)
        {
            return context.MemberRoles.Where(where1 => where1.ApplicationName == applicationName && where1.UserName == userName).ToList();
        }

        public List<MemberRole> GetByRole(string applicationName, string roleName)
        {
            return context.MemberRoles.Where(where1 => where1.ApplicationName == applicationName && where1.RoleName == roleName).ToList();
        }

        public override void Add(MemberRole entity)
        {
            context.AddToMemberRoles(entity);
        }

        public override void Delete(MemberRole entity)
        {
            context.MemberRoles.DeleteObject(entity);
        }

        public override List<MemberRole> All()
        {
            return context.MemberRoles.ToList();
        }
    }
}
